//
// Created by htlin on 2021/3/2 0002.
//

#include "RunnableImpl.h"
#include "encapsulation/ThreadAsync.h"
#include <iostream>
#include <unistd.h>

void RunnableImpl::run() {
  sleep(1);
  std::cout << "thread id: " << pthread_self() << " num:" << num << std::endl;
  if (nullptr != threadAsync) {
    threadAsync->sendAsync((void *) &(++num));
  }
//  sleep(2);
}

RunnableImpl::RunnableImpl(int num, ThreadAsync *threadAsync) : num(num), threadAsync(threadAsync) {

}

RunnableImpl::~RunnableImpl() {
}

void RunnableImpl::finish(bool isCancel) {
  if (isCancel) {
    std::cout << "num is:" << num << ", task is cancel" << std::endl;
  } else {
    std::cout << "num is:" << num << ", task run finish" << std::endl;
  }
}
